package shiyan6;

import shiyan6.*;
import java.io.*;

public class XuankeSystem implements Serializable{
    public static void main(String[] args) throws IOException{
        Course lssx=new Course("001","离散数学","教300","周一10：00——11：40");
        Course xxds=new Course("002","线性代数","教305","周二8：00——9：40");
        Course java=new Course("003","Java","教207","周三1：30——3：10");
        Course cyy=new Course("004","C语言","教202","周四1：30——3：10");
        Course dxwl=new Course("005","大学物理","教201","周五8：00——9：40");
        Course tiyu=new Course("006","体育","综0921","周五10：00——11：40");

        Teacher wang=new Teacher("0001","王老师","男", new Course[]{lssx,xxds});
        Teacher zhang=new Teacher("0002","王老师","男",new Course[]{java,cyy});
        Teacher li=new Teacher("0003","张老师","女",new Course[]{dxwl});
        Teacher shi=new Teacher("004","张老师","男",new Course[]{tiyu});

        lssx.setTeacher(wang);
        xxds.setTeacher(wang);
        java.setTeacher(zhang);
        cyy.setTeacher(zhang);
        dxwl.setTeacher(li);
        tiyu.setTeacher(shi);

        Student liu=new Student("202001","刘同学","男",new Course[3]);
        Student zhao=new Student("202012","赵同学","女",new Course[3]);
         
        liu.xuanke(lssx);
        liu.xuanke(xxds);
        liu.xuanke(java);
        zhao.xuanke(cyy);
        zhao.xuanke(dxwl);
        zhao.xuanke(tiyu);
        liu.tuike(lssx);
        zhao.tuike(cyy);

        Student sOut1=new Student();
        Student sOut2=new Student();
        
        FileOutputStream in = new FileOutputStream("D:\\javazuoye\\Test.txt");
        ObjectOutputStream inin = new ObjectOutputStream(in);
        inin.writeObject(liu);
        inin.writeObject(zhao);

        FileInputStream out=new FileInputStream("D:\\javazuoye\\Test.txt");
        ObjectInputStream otot = new ObjectInputStream(out);
        try {
            sOut1= (Student)otot.readObject();
            sOut2= (Student)otot.readObject();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println("学生编号:"+liu.number+
                "\n学生姓名:"+liu.name+
                "\n学生性别:"+liu.sex);

        for(int i = 0; i<liu.course.length; i++){
            System.out.println("课程编号:"+liu.course[i].number+"\t课程名称:"+liu.course[i].name+"\t上课时间:"
                    +liu.course[i].time+"\t上课地点:"+liu.course[i].place+"\t教师:"+liu.course[i].teacher.name);
        }

        System.out.println("\n"+"学生编号:"+zhao.number+
                "\n学生姓名:"+zhao.name+
                "\n学生性别:"+zhao.sex);

        for(int i = 0; i<zhao.course.length; i++){
            System.out.println("课程编号:"+zhao.course[i].number+"\t课程名称:"+zhao.course[i].name+"\t上课时间:"
                    +zhao.course[i].time+"\t上课地点:"+zhao.course[i].place+"\t教师:"+zhao.course[i].teacher.name);
        }
    }
}